<?php

namespace app\api\controller;

use app\admin\service\Auth;
use DI\Annotation\Inject;
use support\annotation\api\ApiDesc;
use support\annotation\api\ApiGroup;
use support\annotation\api\ApiHeader;
use support\annotation\api\ApiParam;
use support\annotation\api\ApiReturn;
use support\annotation\api\ApiReturnParam;
use support\Request;

/**
 * @ApiGroup(name="管理员接口")
 */
class Admin extends BaseController
{
    /**
     * @Inject()
     * @var Auth
     */
    protected $authService;

    /**
     * @ApiDesc(title="登录",method="POST",route="/api/admin/login",summary="管理员登录接口")
     * @ApiParam(field="username",type="string",required=true,des="账号")
     * @ApiParam(field="password",type="string",required=true,des="密码")
     * @ApiReturn(data={"code":1,"msg":"登录成功","data":{"token":"12345"}})
     * @ApiReturn(title="错误反参", data={"code":0,"msg":"验证码错误","data":{}})
     * @ApiReturnParam(field="token",type="string",sample="12345",des="token 需要的接口必传")
     */
    public function login()
    {
        // 模拟接口登录
        $this->success("登录成功!", [
            'token' => 123
        ]);
    }

    /**
     * @ApiDesc(title="测试是否登录",method="GET",route="/api/admin/test",summary="测试是否登录")
     * @ApiHeader(field="token",type="string",required=true,des="token")
     */
    public function test(Request $request) {
        $token = $request->header('token');
        if ($token == 123) {
            $this->success("已登录");
        }
        $this->error("未登录");
    }
}
